<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>活动页</title>
    <link rel="stylesheet" href="styles/base.css">
    <link rel="stylesheet" href="styles/common.css">
    <link rel="stylesheet" type="text/css" href="styles/applyfor.css"/>
    <style>
        .pageMain{  display: flex;  flex-direction: column;  height: 100%;  }
        header{flex: 0 0 auto;  }
    </style>
</head>
<body>
    <div class="pageMain">
        <header id="header">
            <span class="title_name">连长申请</span>
        </header>
        <section class="page" style="flex: 1 0 auto;">
            <div class="register">
                <form id="myForm">
                    <div class="flex">
                        <div class="label icon-user">姓名：</div>
                        <input placeholder="请输入您的姓名" name="name" type="text" class="input name"/>
                        <span class='error error-name'>请输入姓名！</span>
                    </div>
                    <div class="flex">
                        <div class="label icon-phone">电话：</div>
                        <input placeholder="请输入您的电话" type="text" name="tel" class="input tel"/>
                        <span class='error error-phone'>手机号错误！</span>
                    </div>
                    <button class="signup-btn" type="button">提交审核</button>
                </form>

            </div>
        </section>
        <div class="bottomtext">
            购买成功后，自动成为课代表，可发展新生/转介绍购买课程，下级成功转介绍新生，可获得10元奖励。
        </div>
    </div>
    <div class="msg"></div>


<script type="text/javascript" src="js/zepto.min.js"></script>
<script src="https://cdn.bootcss.com/sweetalert/2.0.2/sweetalert.min.js"></script>
<script src="js/common.js"></script>
<script>
    changePx(); //改变根元素的px
    var getSearchObj = getSerch(location.search);
	$(function(){
        var $msg=decodeURI(getSearchObj.msg)
        if(!!$msg){
            $('.pageMain').hide();
            $(".msg").html($msg).show();
            return;
        }
        $(".pageMain").show();
        // 按钮提交
        $(".signup-btn").click(function(){
            var name=$(".name").val(),phone = $(".tel").val();
            if(!name){
                $(".error-name").show();
                return;
            }
            if( !(/^[1][3,4,5,7,8][0-9]{9}$/.test(phone))) {
                $(".error-phone").show();
                return;
            }
            var arrjson = {'name':name,'mobile':phone,'openId':getSearchObj.openId,'type':'1'}

            $.ajax({
                type: "POST",
                contentType: "application/json;charset=UTF-8",
                url: "http://api.ucmd.cn/renren-api/act/activityagent",
                data:  JSON.stringify(arrjson),
                dataType: 'json',
                success: function(result) {
                    if(result.code == 0) {
						swal("提交成功")
							.then((value) => {
							  window.location.href = "http://api.ucmd.cn/renren-api/wx/activity/wxc57d0b29494417fe/oauth?state=1";
							});
					} else {
                        swal({
                            title:result.msg,
                            type:'type'
                        }).then((value) => {
							  window.location.href = "http://api.ucmd.cn/renren-api/wx/activity/wxc57d0b29494417fe/oauth?state=1";
							});
                    }
                }
            });
        })
		
		wx.ready(function() {
			wx.onMenuShareTimeline({
				title: "课代表申请", // 分享标题
				desc: "我正在申请课代表,一起来赚金币吧。",
				link: "http://api.ucmd.cn/renren-api/wx/activity/wxd06ff3c3a026d169/oauth?state=2", // 分享链接
				imgUrl: "http://pnxb7t5qx.bkt.clouddn.com/upload/20190317/8792b17b8c8e459e9dd28e4f3b614e1e.png", // 分享图标
				success: function() {
					alert("成功");
				},
				cancel: function() {
					alert("失败")
				}
			});
		
			wx.onMenuShareAppMessage({
				title: "课代表申请", // 分享标题
				desc: "我正在申请课代表,一起来赚金币吧。",
				link: "http://api.ucmd.cn/renren-api/wx/activity/wxc57d0b29494417fe/oauth?state=2", // 分享链接
				imgUrl: "http://pnxb7t5qx.bkt.clouddn.com/upload/20190317/8792b17b8c8e459e9dd28e4f3b614e1e.png", // 分享图标
				success: function() {
					alert("成功");
				},
				cancel: function() {
					alert("失败")
				}
			});
			wx.error(function(res){
				// config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
				// alert("errorMSG:"+activityDTO.title+JSON.stringify(res));
			});
		});
    })
</script>
</body>
</html>